package com.tanhua.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.db.Log;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

public interface LogMapper extends BaseMapper<Log> {

    //#新注册用户数,或者用户今日登录数
    @Select("SELECT count(*) from tb_log WHERE type=#{type} AND log_time=#{logTime}")
    Integer queryByTypeAndLogTime(@Param("type") String type, @Param("logTime") String logTime);


    //活跃用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{logTime}")
    Integer queryByLogTime(String logTime);

    //次日留存用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} AND user_id IN \n" +
            " (SELECT user_id FROM tb_log WHERE TYPE='0102' AND log_time=#{yesterday})")
    Integer queryNumRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);


    //累计用户
    @Select("SELECT COUNT(user_id) FROM tb_log WHERE type='0102'")
    Integer queryCumulativeUsers();

    //过去几天活跃用户  查询7天和30天活跃用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log where log_time BETWEEN  #{day}  and  #{today}")
    Integer queryActivePass(@Param("today") String today, @Param("day") String day);

}
